from django.contrib.auth.models import User
from django.core.validators import MinValueValidator
from django.db import models


# Create your models here.
class Classify(models.Model):
    name = models.CharField(max_length=30, unique=True)

    def __str__(self):
        return 'Classify<name=%s>' % self.name


class Label(models.Model):
    name = models.CharField(max_length=30, unique=True, verbose_name="标签")

    def __str__(self):
        return 'Label<name=%s>' % self.name


class UserDetail(models.Model):
    SEX_CHOICES = (
        (0, '男'),
        (1, '女'),
    )
    nickname = models.CharField(max_length=30, verbose_name="昵称")
    age = models.IntegerField(null=True, blank=True, verbose_name="年龄")
    sex = models.IntegerField(null=True, blank=True, verbose_name="性别", choices=SEX_CHOICES)
    birthday = models.DateField(null=True, blank=True, verbose_name="生日")
    QQ = models.CharField(max_length=20, null=True, blank=True, verbose_name="QQ")
    user = models.OneToOneField(User, on_delete=models.CASCADE, verbose_name="用户")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")


class Records(models.Model):
    title = models.CharField(max_length=30, verbose_name="标题", null=True, blank=True)
    description = models.CharField(max_length=100, verbose_name="描述", null=True, blank=True)
    content = models.TextField(null=True, blank=True, verbose_name="内容")
    picture = models.TextField(null=True, blank=True, verbose_name="图片")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    classify = models.ForeignKey(Classify, on_delete=models.NOT_PROVIDED)
    label = models.ManyToManyField(Label)

    def __str__(self):
        return 'Records<title=%s>' % self.title
